<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Goodsval_mdl extends CI_Model {

    const TABLE = 'goods_value';

    public function select(){
        return $this->db->get(self::TABLE)->result_array();
    }

    public function create($data){
        return $this->db->insert(self::TABLE,$data);
    }

    public function get_one(){
        return $this->db->get(self::TABLE)->row_array();
    }

    public function delete(){
        $res = $this->db->delete(self::TABLE);
        return $res;
    }

    public function update($data){
        return $this->db->update(self::TABLE,$data);
    }
    
    /**
     * 组装数据
     */
    public function assembly($list){
    	$data = array();
    	foreach($list as $k => $v){
    		if(empty($v['pid'])){
    			continue;
    		}
    		
    		$this->db->where('id',$v['pid']);
    		$res = $this->get_one();
    		
    		$data[$k] = array(
    				'key' => $res['field'],
    				'val' => $v['field'],
    		);
    		
    		if($v['status'] == 2){
    			$data[$k]['price'] = $v['price'];
    		}
    	}
    	return $data;
    }

}

/* End of file goodsval_mdl.php */
/* Location: ./application/models/goodsval_mdl.php */